const mongoose = require('mongoose');
const { User } = require('../../model/user')
const bcrypt = require('bcrypt')

module.exports = async (req, res) => {
     let { password, newpassword } = req.fields
    const user = await User.findOne()
    // 对比密码
    let isValid = await bcrypt.compare(password, user.password);
    if (isValid) {
        const salt = await bcrypt.genSalt(10);
        // 加密
        password = await bcrypt.hash(newpassword, salt);
        const data = await User.updateOne({ username: user.username }, { password: password })
        res.send({
            data: null,
            meta: {
                status: 203,
                msg: '修改成功'
            }
        })
    } else {
        res.send({
            data: null,
            meta: {
                status: 400,
                msg: '请求失败'
            }
        })
    }
}






